import {
  Component,
  EventEmitter, inject, Input,
  Output
} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {type NewTaskData} from '../task/task.model';
import {TasksService} from '../tasks.service';

@Component({
  selector: 'app-new-task',
  standalone:false,
  templateUrl: './new-task.html',
  styleUrl: './new-task.css'
})
export class NewTask {
  @Input ({required:true}) userId!:string;
  @Output() close = new EventEmitter<void>();

  enteredTitle = '';
  enteredSummary ='';
  enteredDate ='';
  private tasksService = inject(TasksService);


  onCancel(){
    this.close.emit();
  }

  onSubmit(){
    this.tasksService.addTask({
      title:this.enteredTitle,
      summary:this.enteredSummary,
      date:this.enteredDate,
    },
      this.userId
    );
    this.close.emit();
  }
}
